package org.raymond.iworks.study.startup;

import lombok.extern.slf4j.Slf4j;
import org.raymond.iworks.commons.utils.NetworkUtil;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.context.ApplicationListener;

import java.io.IOException;

/**
 * @author raymond
 * @version V1.0
 * @Description: TODO
 */
@Slf4j
public class AppStart21 implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {
    @Override
    public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
        try {
            int port = NetworkUtil.randomPort(13100, 13200);
            System.setProperty("server.port", String.valueOf(port));
            log.info("AppStart21 end. set port: {}", port);
        } catch (IOException e) {
            log.error(e.getMessage());
        }
    }
}
